package com.sau.pixelcart.mapper;

import com.sau.pixelcart.domain.entity.InventoryAlert;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

/**
 * <p>
 * 库存预警事件表 Mapper 接口
 * </p>
 *
 * @author Inton
 * @since 2025-03-08
 */

@Mapper
public interface InventoryAlertMapper extends BaseMapper<InventoryAlert> {

    /**
     * 设置预警状态为已处理
     */
    void processAlert(@Param("productId") String productId,@Param("status") String status,@Param("userId") String userId,@Param("processedTime") LocalDateTime processedTime);

    /**
     * 更新当前库存
     * @param productId
     * @param stock
     */
    @Update("update inventory_alert set current_stock = #{stock} where product_id = #{productId} and status = 'pending'")
    void updateCurrentStock(@Param("productId") String productId, @Param("stock") Integer stock);
}
